
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import org.apache.commons.daemon.Daemon;
import org.apache.commons.daemon.DaemonContext;
import org.apache.log4j.Logger;

import org.sopt.dev.ImgKnight.agent.Agent;

public class AgentWrapper implements Daemon {

	Agent agent = Agent.getInstance();
	
	Logger exceptionLogger = Logger.getLogger("agent.exception");
	
	public static SimpleDateFormat df = new SimpleDateFormat("[E MMM dd HH:mm:ss]", Locale.UK);
	
	@Override
	public void init(DaemonContext arg0) throws Exception {
		try {
			agent.init();
		}catch (Exception e) {
			System.err.println(e);
			throw e;
		}
		System.out.println(df.format(new Date())+" agent init\t[OK]");
	}

	@Override
	public void start() throws Exception {
		try {
			agent.run();
		}catch (Exception e) {
			System.err.println(e);
			throw e;
		}
		System.out.println(df.format(new Date())+" agent start\t[OK]");
	}

	@Override
	public void stop() throws Exception {
		try {
			agent.shutdown();
		}catch (Exception e) {
			System.err.println(e);
			throw e;
		}
		System.out.println(df.format(new Date())+" agent stop\t[OK]");
	}
	
	@Override
	public void destroy() {
		/**/
	}
	
}
